package com.ruoyi.common.config;

import org.springframework.stereotype.Component;

/**
 * 金融数据缓存配置类
 * 统一管理金融数据相关的缓存配置
 */
@Component
public class FinancialDataCacheConfig {
    
    /**
     * API原始数据缓存时间（秒）
     */
    public static final int API_RAW_DATA_CACHE_SECONDS = 30;
    
    /**
     * 处理后数据缓存时间（秒）
     */
    public static final int PROCESSED_DATA_CACHE_SECONDS = 60;
    
    /**
     * 缓存刷新间隔（秒）
     */
    public static final int CACHE_REFRESH_INTERVAL = 15;
    
    /**
     * API调用失败重试次数
     */
    public static final int API_RETRY_COUNT = 3;
    
    /**
     * API调用超时时间（毫秒）
     */
    public static final int API_TIMEOUT_MS = 10000;
    
    /**
     * 批量获取数据时的最大并发数
     */
    public static final int MAX_CONCURRENT_REQUESTS = 5;
    
    /**
     * 支持的外汇货币对
     */
    public static final String[] FOREX_SYMBOLS = {
        // 主要外汇对
        "EURUSD", "GBPUSD", "USDJPY", "USDCHF", "AUDUSD", "NZDUSD", "USDCAD",
        // 交叉汇率 - EUR系列
        "EURGBP", "EURJPY", "EURCHF", "EURNZD", "EURAUD", "EURCAD", "EURCNY", "EURTRY",
        // 交叉汇率 - GBP系列
        "GBPJPY", "GBPCHF", "GBPCAD", "GBPAUD", "GBPNZD", "GBPCNY",
        // 交叉汇率 - AUD系列
        "AUDJPY", "AUDCHF", "AUDCAD", "AUDNZD", "AUDCNY",
        // 交叉汇率 - NZD系列
        "NZDJPY", "NZDCHF", "NZDCAD",
        // 交叉汇率 - JPY系列
        "CHFJPY", "CADJPY", "CNYJPY",
        // 交叉汇率 - CHF系列
        "CADCHF",
        // 交叉汇率 - CNY系列
        "CNYHKD", "CADCNY",
        // 其他外汇对
        "USDHKD", "USDCNY", "USDCNH", "USDKRW", "USDMXN", "USDTRY", "USDZAR", 
        "USDDKK", "USDNOK", "USDRUB", "USDSEK", "USDSGD"
    };
    
    /**
     * 支持的贵金属品种（仅黄金）
     */
    public static final String[] METAL_SYMBOLS = {
        "GOLD", "XAU", "XAUUSD"
    };
    
    /**
     * 支持的商品品种（已禁用，不再请求外部API）
     */
    public static final String[] COMMODITY_SYMBOLS = {
        // 已禁用商品数据请求，如需要请取消注释
        // "OIL", "CRUDE", "USOIL", "GAS", "NGAS", "BRENT", "UKOIL", "HEATING"
    };
    
    /**
     * 获取缓存键前缀
     */
    public static String getCacheKeyPrefix(String dataType) {
        switch (dataType.toLowerCase()) {
            case "forex":
                return "FOREX_DATA_CACHE";
            case "metal":
                return "METAL_DATA_CACHE";
            case "commodity":
                return "COMMODITY_DATA_CACHE";
            default:
                return "FINANCIAL_API_RAW_DATA";
        }
    }
    
    /**
     * 判断是否为外汇品种
     */
    public static boolean isForexSymbol(String symbol) {
        String upperSymbol = symbol.toUpperCase();
        for (String forex : FOREX_SYMBOLS) {
            if (forex.equals(upperSymbol)) {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 判断是否为贵金属品种
     */
    public static boolean isMetalSymbol(String symbol) {
        String upperSymbol = symbol.toUpperCase();
        for (String metal : METAL_SYMBOLS) {
            if (metal.equals(upperSymbol)) {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 判断是否为商品品种
     */
    public static boolean isCommoditySymbol(String symbol) {
        String upperSymbol = symbol.toUpperCase();
        for (String commodity : COMMODITY_SYMBOLS) {
            if (commodity.equals(upperSymbol)) {
                return true;
            }
        }
        return false;
    }
} 